package Model.Animals;

import Model.Animals.Behaviours.*;
import Model.*;
import java.util.ArrayList;

/**
 *
 * @author HOANG TRUONG DINH
 */
public abstract class Animal extends Entity {

    //int id;
    ArrayList<Performable> performables;
    Chaseable chaseable;
    Eatable eatable;
    Flyable flyable;
    Swimable swimable;
    Walkable walkable;
    int level;
    boolean crossbreedable;
    String description = "Unknown Animal";
    double cost;
    int heathly;

//    public Animal(String ref, int x, int y) {
//        super(ref, x, y);
//        level = 1;
//    }
    public Animal() {
        level = 1;
        cost = 0;
        heathly = 1000;
        performables = new ArrayList<Performable>();
    }

    public String getDescription() {
        return description;
    }

    public double upgradeCost() {
        if (level < 3) {
            return cost * 0.5;
        } else {
            return -1;
        }
    }

    public void upgrade() {
        if (level < 3) {
            level++;
            cost = cost * 1.5;
        }
    }

    public abstract double calCost();

    public ArrayList<Performable> getPerformables() {
        return performables;
    }

    public Chaseable getChaseable() {
        return chaseable;
    }

    public void setChaseable(Chaseable chaseable) {
        this.chaseable = chaseable;
    }

    public boolean isCrossbreedable() {
        return crossbreedable;
    }

    public void setCrossbreedable(boolean crossbreedable) {
        this.crossbreedable = crossbreedable;
    }

    public Eatable getEatable() {
        return eatable;
    }

    public void setEatable(Eatable eatable) {
        this.eatable = eatable;
    }

    public Flyable getFlyable() {
        return flyable;
    }

    public void setFlyable(Flyable flyable) {
        this.flyable = flyable;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public Swimable getSwimable() {
        return swimable;
    }

    public void setSwimable(Swimable swimable) {
        this.swimable = swimable;
    }

    public Walkable getWalkable() {
        return walkable;
    }

    public void setWalkable(Walkable walkable) {
        this.walkable = walkable;
    }

    public void addPerformable(Performable performable) {
        performables.add(performable);
    }

    @Override
    public void run() {
        while (heathly > 0) {
            this.live();
        }
    }

    public void live() {
        System.out.print(heathly + "_" + this.getDescription() + "_");
        heathly-=5;
        if (heathly > 500) {
            for (Performable performable : performables) {
                heathly -= performable.perform();
                long startingTime = System.currentTimeMillis();
                long timePassed = System.currentTimeMillis() - startingTime;

                while (timePassed < 10000) {
                    heathly -= walkable.walk();
                    heathly -= swimable.swim();
                    heathly -= flyable.fly();
                    timePassed+=3000;
                }
            }
        } else {
            if (heathly >= 250) {
                System.out.println("I'm sleeping");
            } else if (heathly >= 101 && heathly < 250) {
                System.out.println("I'm hungry");
            } else if (heathly >= 11 && heathly < 101) {
                System.out.println("I'm starving");
            } else if (heathly > 0 && heathly < 11) {
                System.out.println("I'm dying");
            } else if (heathly <= 0) {
                System.out.println("I'm died");
            }
        }
    }
}
